package com.wybx.web;

import com.wybx.pojo.OrderInfoBO;
import com.wybx.pojo.SpeedCount;
import com.wybx.pojo.Student;
import com.wybx.serivce.SpeedCountService;
import com.wybx.serivce.WybzService;
import com.wybx.serivce.XszcService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
public class WybzController {

    @Autowired
    private WybzService wybzService;

    @Autowired
    private XszcService xszcService;

    @Autowired
    private SpeedCountService speedCountService;
    @RequestMapping("/wybz/index")
    public String index(){

        return "index";
    }

    @RequestMapping("/xszc/index1")
    public String index1(){

        return "index3";
    }


    @RequestMapping("/wybx/getData")
    @ResponseBody
    public List<OrderInfoBO> getData(){
        //添加当前时间
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
        String createTime = dateFormat.format(now);//格式化然后放入字符串中


        List<OrderInfoBO> orderInfoList = wybzService.getOrderInfoByCreateTime("2020-07-13");
        if (orderInfoList.size() == 0 || orderInfoList.isEmpty()){
            return new ArrayList<>();
        }else {
            return orderInfoList;
        }
    }


    @RequestMapping("/xszc/getData")
    @ResponseBody
    public Student getData1(@RequestParam("id") int id){
        return xszcService.getNameList(id);
    }

    @RequestMapping("/xszc/getSpeedCount")
    @ResponseBody
    public SpeedCount getSpeedCount(){
        return speedCountService.getSpeedCount();
    }
    @RequestMapping("/xszc/getRegisterMaxId")
    @ResponseBody
    public Integer getRegisterMaxId(){
        return xszcService.getRegisterMaxId();
    }
}
